home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / newmarch.zip / DRAW.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  4KB  |  126 lines

  1. /* Author:   $Author: jan $
  2.  * File:     $Source: /usr/usrs/jan/desktop/X_Book.boo/programs/RCS/draw.c,v $
  3.  * Date:     $Date: 1992/09/09 00:09:51 $
  4.  * Revision: $Revision: 1.1 $
  5.  */
  6.  
  7. #include "copyright.h"
  8.  
  9. #include <stdio.h> 
  10.  
  11. #include <Xm/DrawingA.h> 
  12.  
  13. /*------------------------------------------------------------- 
  14. **     Forward Declarations 
  15. */ 
  16.  
  17. void main ();            /*  main logic for application    */ 
  18. void CreateApplication ();    /*  create main window        */ 
  19. void display_somethingCB ();            /*  callback for quit button    */ 
  20.  
  21. /*------------------------------------------------------------- 
  22. **    Global Variables 
  23. */ 
  24.  
  25. #define MAX_ARGS 20 
  26. #define Class_name "Draw" 
  27.  
  28. Widget  draw_area;   /*  Drawing Area widget              */ 
  29. Display *display;    /* the display device                */    
  30. int     screen;      /* the screen on the display         */    
  31. Window  draw_window; /* the drawing area widgets's window */   
  32. GC      gc;    
  33.  
  34.     
  35. /*------------------------------------------------------------- 
  36. ** Create a graphics context using default values, and    
  37. ** return it in the pointer gc    
  38. */    
  39. GC
  40. getGC ()
  41. {   GC gc;    
  42.     
  43.  
  44.     gc = XCreateGC (display, draw_window,     
  45.                 (unsigned long) 0, NULL);    
  46.     
  47.     XSetForeground (display, gc, (unsigned long) 1);
  48.     XSetBackground (display, gc,(unsigned long) 0);
  49.     return (gc);
  50. }    
  51.     
  52. /*------------------------------------------------------------- 
  53. ** Write a string    
  54. ** and draw a circle   
  55. */    
  56. void display_somethingCB (w, client_data, call_data)  
  57. Widget        w;        /*  widget id        */ 
  58. caddr_t       client_data;    /*  data from application   */ 
  59. caddr_t       call_data;    /*  data from widget class  */ 
  60. {
  61.     /* the proverbial string */    
  62.     XDrawImageString (display, draw_window, gc,    
  63.                       10, 10, "Hello world",    
  64.                       strlen ("Hello world"));    
  65.     
  66.     /* and a world (circle) to go with it */    
  67.     XDrawArc (display, draw_window, gc,    
  68.                30, 30,
  69.                100, 100, 
  70.                0, 360*64);
  71.     XFlush (display);
  72. }    
  73. /*------------------------------------------------------------- 
  74. **    main        - main logic for application 
  75. */ 
  76. void main (argc,argv)  
  77.     unsigned int    argc; 
  78.     char         **argv; 
  79.     Widget        app_shell;    /*  ApplicationShell    */ 
  80.  
  81.      /*    Initialize toolkit, open the display and create the toplevel widget. */ 
  82.     app_shell = XtInitialize(argv[0], /* application name */    
  83.                Class_name,     /* class name */    
  84.                NULL,         /* options */    
  85.                0,        /* number of options */    
  86.                &argc, argv);    
  87.   
  88.     /* set up all the sub-widgets */ 
  89.     CreateApplication(app_shell);
  90.     XtRealizeWidget (app_shell); 
  91.  
  92.     /* Now get info about windows, etc 
  93.     ** The XtWindow() _must_ occur after XtRealize() has
  94.     ** created the Drawing Area's window
  95.     */
  96.     display = XtDisplay (draw_area);
  97.     draw_window = XtWindow (draw_area);
  98.     gc = getGC ();
  99.  
  100.     /*    Get and dispatch events. 
  101.     */ 
  102.     XtMainLoop (); 
  103.  
  104. /*------------------------------------------------------------- 
  105. **     CreateApplication    - create main window 
  106. */ 
  107. void CreateApplication (parent)  
  108. Widget        parent;        /*  parent widget    */ 
  109.  
  110.      Arg        args[MAX_ARGS];    /*  arg list        */ 
  111.      register int    n;        /*  arg count        */ 
  112.  
  113.      /*    Create Drawing Area
  114.      **    Make it a reasonable size
  115.      */ 
  116.      n = 0; 
  117.      XtSetArg (args[n], XmNwidth, 300); n++;
  118.      XtSetArg (args[n], XmNheight, 300); n++;
  119.      draw_area = XmCreateDrawingArea (parent, "an_area", args, n);    
  120.      XtAddCallback (draw_area, XmNexposeCallback, display_somethingCB);
  121.      XtManageChild (draw_area);     
  122.